<?php

require_once("conexao.php");
$servico = $_POST["servico"];
$valor = $_POST["valor"];
$valor = str_replace(",",".",$valor);
$descricao = $_POST["descricao"];
$query = "select * from tbservico where ";
 
	if($servico == null && $valor == null && $descricao == null){
		$rest = "select * from tbservico";
	}else{
		if($servico != null){
			$query = $query."servico like '%".$servico."%' and ";
		}
		if($valor != null){
			$query = $query."valor = $valor and ";
		}
		if($descricao != null){
			$query = $query."descricao like '%".$descricao."%' and";	
		}
		$rest = substr("$query", 0, -4);
	}
	$resource_result = pg_query($rest);
	$resultado = pg_fetch_all($resource_result);
	foreach($resultado as $r){
		echo 'Serviço:',$r['servico'],"<br />",'Valor:'.$r['valor'],"<br />",'Descrição:'.$r['descricao'],"<br />","<br />";
	}
?>
